<!doctype html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  <title>充值</title>
  <link rel="stylesheet" type="text/css" href="../css/api.css" />
  <link rel="stylesheet" type="text/css" href="../css/recharge.css" />
</head>

<body>
  <div id="app" v-cloak>
    <div class="wrap flex-wrap flex-vertical">
      <header id="header">
        <div class="header-wrap border-bottom">
          <div @click="goback" class="header-left">
            <i class="iconfont icon-pre"></i>
          </div>
          <div class="header-title">充值</div>
        </div>
      </header>
      <div class="recharge-title">
        <div class="recharge-title-t">
          <!-- <img class="zuan-icon" src="../image/zuan1_icon.png" alt=""> -->
          <i class="icon icon-gold"></i>
          <span>我的港币</span>
        </div>
        <div class="recharge-title-b">{{info.gold}}</div>
      </div>
      <div class="recharge-con">
        <div class="flex-item rechargeList" v-for="(item, i) in list" :key="item.id">
          <div class="rechargeList-l">
            <div class="rechargeList-title">{{item.gold}}港币</div>
            <div class="rechargeList-info"><span v-if="item.give != '0'">+ {{item.give}}港币</span><span v-if="item.give_vip != '0'">+ {{item.give_vip}}天VIP</span></div>
          </div>
          <div class="rechargeList-r">
            <span :id="item.id" @click="pay(item)">￥{{item.price}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
  var app;
  apiready = function () {
    $api.fixStatusBar($api.dom('#header'));
    app = new Vue({
      el: '#app',
      data: {
        info: {
          gold: '',
        },
        list: [],
        isPaying: false,
      },
      created: function () {
        var _this = this;
        api.addEventListener({
          name: 'keyback'
        }, function(ret, err){
          if (_this.isPaying) {
            api.closeFrame({
              name: 'pay_frame'
            });
            api.closeFrame({
              name: 'pay_frame2'
            });
            _this.isPaying = false;
          } else {
            _this.goback();
          }
        });
        api.addEventListener({
          name: 'setPaying_false'
        }, function(ret, err){
          _this.isPaying = false;
        });
      },
      mounted: function () {
        this.getPayGoods();
      },
      methods: {
        getPayGoods: function () {
          var _this = this;
          api.ajax({
            url: baseUrl + 'pay/goods',
            method: 'get',
            headers: {
              token: $api.getStorage('deviceToken')
            },
            data: {
              values: {
                uid: $api.getStorage('uid')
              },
            }
          }, function (ret, err) {
            if (ret.status == 200) {
              _this.info = ret.data.info;
              _this.list = ret.data.list;
            }
          })
        },
        
        pay: function (item) {
          var _this = this;
          _this.isPaying = true;
          // var tempExtra = {
          //   fromId: $api.getStorage('uid'),
          //   fromName: $api.getStorage('uname'),
          //   fromAvatar: $api.getStorage('uavatar'),
          //   toId: '2',
          //   toName: '官方客服',
          //   toAvatar: 'http://file.xdhld.top/default.png',
          //   from: 'pay',
          //   type: 'defaullt',
          //   price: item.price,
          // }
          // api.openWin({
          //   name: 'im',
          //   url: 'im.html',
          //   pageParam: tempExtra
          // });
          // return false;
          api.ajax({
						url: baseUrl + 'device/index',
						method: 'get',
						data: {}
					}, function (ret, err) {
						if (ret.status == 200) {
              if (ret.data.pay == '1') {
                // 官方支付
                api.openFrame({
                  name: 'pay_frame',
                  url: 'pay_frame.html',
                  rect: {
                    x: 0,
                    y: 0,
                    w: api.winWidth,
                    h: api.winHeight
                  },
                  pageParam: {
                    type: 'defaullt',
                    tid: item.id,
                    price: item.price,
                  }
                });
              }
              if (ret.data.pay == '2') {
                // 免签支付
                api.openFrame({
                  name: 'pay_frame2',
                  url: 'pay_frame2.html',
                  rect: {
                    x: 0,
                    y: 0,
                    w: api.winWidth,
                    h: api.winHeight
                  },
                  pageParam: {
                    type: 'defaullt',
                    tid: item.id,
                    price: item.price,
                  }
                });
              }
						} else {
              api.toast({
                msg: '服务器繁忙，请稍后再试',
                duration: 2000,
                location: 'bottom'
              });
            }
					});
        },
        goback: function () {
          api.closeWin();
        },
      },
    })
  }
</script>